<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>修改类别</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../static/layuiAdmin.std-v1.7.1/src/layuiadmin/layui/css/layui.css" media="all">
</head>
<body>
<?php
	$sortid = isset($_GET["sortid"])?$_GET["sortid"]:0;
	if($sortid==0)echo "<script>alert('参数传递错误');history.back();</script>";
	require("../../fun.php");
	isLogin();
	$db = conndb();
	$sql = "select * from sortclass where id=$sortid";
	$row = query1($db,$sql,false);
    $select_trees = select_trees($parentid=0,$db,$currentid=40,$selectname="sortid");
?>
  <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
      <label class="layui-form-label">类别名称</label>
      <div class="layui-input-inline">
        <input type="text" name="sortname"  autocomplete="off" id="sortname" class="layui-input" value="<?php echo $row["sortname"]?>">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">排   序</label>
      <div class="layui-input-inline">
        <input type="text" name="orders"  autocomplete="off" id="orders" class="layui-input" value="<?php echo $row["orders"]?>""  onkeyup="this.value=this.value.replace(/\D/g,'')">
      </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <input type="hidden" name="sortid" value="<?php echo $sortid;?>" />
        <input type="hidden" name="parentid" value="<?php echo $row["parentid"];?>" />
        <input type="button" class="layui-btn" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="修改分类">
    </div>
  </div>

  <script src="../../static/layuiAdmin.std-v1.7.1/src/layuiadmin/layui/layui.js"></script>  
  <script>
  layui.config({
    base: '../../static/layuiAdmin.std-v1.7.1/src/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form'], function(){
    var $ = layui.$
    ,form = layui.form;

    $(function(e){
        $("#layuiadmin-app-form-edit").click(function(e) {
            var sortname = $("#sortname").val();
            var orders = $("#orders").val();
            if(sortname==""){layer.msg("类别名称不能为空");$("#sortname").focus(); return false;}
            $("form").submit();
        });
    })
    
    //监听提交
    form.on('submit(layuiadmin-app-form-edit)', function(data){
        var field = data.field; //获取提交的字段
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  

        //提交 Ajax 成功后，关闭当前弹层并重载表格
        //$.ajax({});
        layer.confirm('您确定修改类别吗？', function() {
            $.ajax({
                type: "post",
                url: "./save.php",
                data: data.field,
                dataType: "json",
                success: function(res) {
                    if (res.code==1) {
                        layer.msg(res.msg,{icon:1,time:2000},function () {
                            $("#sortname").focus()
                            history.back();
                        })
                    }
                    if (res.code == 0) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 2000
                        }, function() {
                            parent.location.href="./index.php";
                        })
                    }
                    if (res.code == 2) {
                        layer.confirm(res.msg, function() {
                            parent.location.href="./index.php";
                        })
                    }
                }
            })
        });
    });
  })
  </script>
</body>
</html>